import * as tracer from 'tracer';
import * as path from 'path';
import { appConfig } from '../app.config';

class Console {
    logger = tracer.colorConsole();

    constructor() {
        if (!appConfig.debug) {
            this.logger = tracer.dailyfile({
                root: path.resolve(__dirname, '../../', 'logs'),
                maxLogFiles: 10,
                format: [
                    '{{timestamp}} <{{title}}> {{message}} (in {{file}}:{{line}})',
                    { error: '{{timestamp}} <{{title}}> {{message}} (in {{file}}:{{line}})\n{{stack}}' }
                ],
                dateformat: 'HH:MM:ss.L',
                preprocess: function (data) {
                    data.title = data.title.toUpperCase();
                },
                level: 'debug',
            });
        }
    }

    log(...args: any[]) {
        return this.logger.log(args);
    }

    trace(...args: any[]) {
        return this.logger.trace(args);
    }

    debug(...args: any[]) {
        return this.logger.debug(args);
    }

    info(...args: any[]) {
        return this.logger.info(args);
    }

    warn(...args: any[]) {
        return this.logger.warn(args);
    }

    error(...args: any[]) {
        return this.logger.error(args);
    }
}

export default new Console();
